package com.himilco.ocana.gui.serviceProvider;

import com.himilco.ocana.workflow.core.bo.ServiceProviderBO;
import com.himilco.ocana.workflow.core.dao.entities.Ticket;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "spc")
@SessionScoped
public class ServiceProviderContoller implements Serializable {

    @EJB
    private ServiceProviderBO spBO;
    private ServiceProviderModel spm = new ServiceProviderModel();
    private Ticket selectedTicket = new Ticket();

    public Ticket getSelectedTicket() {
        System.out.println("selected ticket invoked!!");

        return selectedTicket;
    }

    public void setSelectedTicket(Ticket selectedTicket) {

        this.selectedTicket = selectedTicket;
    }

    public ServiceProviderContoller() {
    }

    public List<Ticket> getTicketsDispatched() {
        spm.setTicketsDispatched(spBO.findAllDispatchedTickets());
        return spm.getTicketsDispatched();
    }

    public void onRowSelect() {
        System.out.println("Row selected!!");
    }

    public ServiceProviderBO getSpBO() {
        return spBO;
    }

    public ServiceProviderModel getSpm() {
        return spm;
    }

    public void setSpm(ServiceProviderModel spm) {
        this.spm = spm;
    }

    public void checkConfirmation() {
        System.out.println("save pushed");
        System.out.println("buttom checked status: " + spm.isValue2());
        if (spm.isValue2()) {
            System.out.println("confirmating SP Tikcet");
            getSpm().getSelectedTicket().setStatus("CONFIRMED_INCIDENT");
            getSpBO().updateTicket(getSpm().getSelectedTicket());
        }
    }
}
